package utilities;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;

import org.apache.commons.io.FileUtils;

public class Utils {

	public static Icon setImageToLabel(String path, Integer width, Integer height) {
		BufferedImage img = null;
		try {
		    img = ImageIO.read(new File(path));
		} catch (IOException e) {
		    e.printStackTrace();
		}
		ImageIcon imageIcon = new ImageIcon(img.getScaledInstance(width, height,
		        Image.SCALE_SMOOTH));
		return imageIcon;
	}
	
	public static void moveFile(String path, Integer id) {
		File sourceFile = new File(path);
		String target = Constants.defaultPath  + id.toString();
        File targetFile = new File(target);
        if (!path.equals(target)){
        	try {
        		FileUtils.copyFile(sourceFile, targetFile);
        	} catch (IOException e) {
        		e.printStackTrace();
        	}
        }
	}
	
}
